package com.example.handler;

import com.example.exception.RedisOpsResultIsNullException;
import com.example.utils.Result;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理之传统web开发
 */
@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(value = Exception.class)
    public Result exceptionHandler(Exception e) {
        e.printStackTrace();
        return Result.error(HttpStatus.INTERNAL_SERVER_ERROR.value(),"服务异常！！");
    }

    @ExceptionHandler(value = RedisOpsResultIsNullException.class)
    public Result exceptionHandler(RedisOpsResultIsNullException e) {
        e.printStackTrace();
        return Result.error(HttpStatus.INTERNAL_SERVER_ERROR.value(),e.getMessage());
    }

}
